<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" import="java.sql.*"%>
<%@ page import="ookweb.Conn"%>
<%@ page import="ookweb.Data"%>
<%@ include file="../public.jsp" %> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/ookweb/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>">    
    <title>信息分类</title>    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<link rel="stylesheet" type="text/css" href="<%=basePath%>/images/m/css.css">
	<script type="text/javascript"> 
        var GB_ROOT_DIR = "<%=basePath%>images/m/greybox/";
	</script>
	<script type="text/javascript" src="<%=basePath%>images/m/greybox/AJS.js"></script>
	<script type="text/javascript" src="<%=basePath%>images/m/greybox/AJS_fx.js"></script>
	<script type="text/javascript" src="<%=basePath%>images/m/greybox/gb_scripts.js"></script>
	<link href="<%=basePath%>images/m/greybox/gb_styles.css" rel="stylesheet" type="text/css" media="all" />
	<script src="<%=basePath%>js/jquery-1.5.1.min.js"  type="text/javascript" ></script>
	<script src="<%=basePath%>js/public.js"  type="text/javascript" ></script>
  </head>
  
  <body><br/>
  <%   Data data=new Data(dbuser,dbpass,dburl);
     Conn con=new Conn(dbuser,dbpass,dburl);
    String cid=(String)request.getParameter("cid");
    String act=(String)request.getParameter("act");
    String sid=(String)request.getParameter("sid");
    if("".equals(sid) || sid==null){sid="0";}
    int intT=0;
    if("d".equals(act) && !("".equals(cid)) && cid!=null){
       int t=data.getRowCount(" web_part where 1=1 and sjid="+cid); //总记录数
       if(t<1){
       data.delete("delete from web_part where partid="+cid);
       }else{
       out.print("<script>alert(\"此栏目有子栏目，请先删除子栏目.\");</script>");
       }  
       act=""; 
          
     }
    if(!("".equals(act) ||  act==null)){
       String classname="",partpath="",isxj="",sort="";
      if("save".equals(act)){
         String sql="";
         classname=(String)request.getParameter("classname");
         partpath=(String)request.getParameter("partpath");
          sort=(String)request.getParameter("sort");
         isxj=(String)request.getParameter("isxj");
         int num=0;
         if(!("".equals(cid)) && cid!=null){
         
         sql="update web_part set partname='"+classname+"',isxj="+isxj+",partpath='"+partpath+"',sort="+sort+" where partid="+cid;
         num=data.update(sql);
         if(num>0){out.print("<script>alert(\"已成功修改\");</script>");}
         }else{
         java.text.SimpleDateFormat formatter=new java.text.SimpleDateFormat("yyyy-MM-dd");
         java.util.Date currentTime=new java.util.Date();
         String time=formatter.format(currentTime);
         sql="insert into web_part(partid,partname,partpath,sjid,isxj,addtime,sort)values(WEB_PART_SEQ.nextval,'"+classname+"','"+partpath+"',"+sid+","+isxj+",to_date('"+time+"','yyyy/mm/dd'),'"+sort+"')";
         num=data.insert(sql);
         if(num>0){out.print("<script>alert(\"已成功添加\");</script>");}
         }
         
      }else if("e".equals(act) && !("".equals(cid)) && cid!=null){	       
			 ResultSet rs=con.getRs("SELECT * FROM web_part where partid="+cid);
			 if(rs.next()){
			 classname=rs.getString("partname");sid=rs.getString("sjid");partpath=rs.getString("partpath");isxj=rs.getString("isxj");sort=rs.getString("sort");
			 }
      }else{cid="";}
      %>
      <form action="<%=basePath%>webadmin/info/part.jsp?act=save&sid=<%=sid %>&cid=<%=cid%>" method="post" id="frm">
	  <table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="92acbb">
	   <tr>
	    <td align="center" width="140">栏目名称</td>
	    <td align="left"><input name="classname" id="classname" type="text" class="inp" value="<%=classname %>"/></td>
	  </tr>
	  <tr>
	    <td align="center" width="140">子栏</td>
	    <td align="left">
	    <select name="isxj">
	    <option value="0"  <% if(isxj.equals("0")){ out.print("selected");} %>>无</option>
	    <option value="1" <% if(isxj.equals("1")){ out.print("selected");} %>>有</option>
	    </select>
	    </td>
	  </tr>
	  <tr>
	    <td align="center" width="140">栏目连接</td>
	    <td align="left"><input name="partpath" id="partpath" type="text" class="inp" value="<%=partpath %>"/></td>
	  </tr>
	  <tr>
	    <td align="center" width="140">排序</td>
	    <td align="left"><input name="sort" id="sort" type="text" class="inp" value="<%=sort %>"/></td>
	  </tr>
	   <tr>
	    <td align="center" width="140">操作</td>
	    <td align="left"> <input name="cmd" id="savecmd" type="button" class="inp" value="保存" style="width:60px;"/></td>
	  </tr>
	 </table>
	 </form>
   <script type="text/javascript">
	$(document).ready(function() {
		$('#savecmd').click(function() {
		  if($('#classname').attr('value')==''){
		  alert('请输入栏目名称');return;
		  }else if($('#partpath').attr('value')==''){
		  alert('请输入栏目路径');return;
		  }else{
		    $("#frm").submit();
		  }
		});
	});
   </script>
   <% }else{%>
  【<span class="bt">栏目管理</span>】
 《<a href="<%=basePath%>webadmin/info/part.jsp?act=a&sid=<%=sid %>" title="增加新栏目" rel="gb_page_center[600,200]">添加新栏目</a>》
 <%if(!("0".equals(sid))){ 
 ResultSet rs=con.getRs("select sid from web_infoclass where classid="+sid);
 String ssid="0";
 if(rs.next()){
 ssid=rs.getString("sid");
 }
 %>
 《<a href="<%=basePath%>webadmin/info/part.jsp?sid=<%=ssid %>" title="反回上级" >反回上级</a>》
  《<a href="<%=basePath%>webadmin/info/part.jsp?sid=0" title="反回顶级" >反回顶级</a>》
 <%}%>
 《<a href="javascript:window.location.reload();" title="反回顶级" >刷新</a>》
 <table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="92acbb">
  <tr>
    <th  align="left">上级类</th>
    <th align="left">栏目</th>
    <th align="center">子栏</th>
    <th width="140">时间</th>
    <th width="160">操作</th>
  </tr>
  <% 
//变量声明 
String mysql=new String(); //SQL语句
mysql=" web_part where 1=1 and sjid="+sid;
int intRowCount=0;  //总的记录数
int intPageCount=0; //总的页数
int intPageSize=15; //每页显示的记录数
int intPage; //待显示页码 
String strPage=new String(); //用来接收当页码参数
int begin_no=0; //开始的rownum记录号
int end_no=0;  //结束的rownum记录号

//取得待显示页码 
strPage = request.getParameter("page"); 
if(strPage==null){//表明在QueryString中没有page这一个参数，此时显示第一页数据 
intPage = 1; 
} 
else{//将字符串转换成整型 
intPage = java.lang.Integer.parseInt(strPage); 
if(intPage<1) intPage = 1; 
} 
//得到总的数据记录行数
intRowCount=data.getRowCount(mysql); //总记录数
//计算总共要分多少页
intPageCount = (intRowCount+intPageSize-1) / intPageSize; 
//调整待显示的页码 
if(intRowCount>0){
if(intPage>intPageCount) intPage = intPageCount; 
	    begin_no=(intPage-1) * intPageSize + 1; 
        end_no = intPage * intPageSize;
	    mysql="select a.*,b.partname as sjname from (select rownum row_id ,partid,partname,sjid,isxj,addtime from (select partid,partname,sjid,isxj,addtime from web_part where sjid="+sid+" order by partid asc)) a";
	    mysql=mysql+" left join web_part b on a.sjid=b.partid where row_id between " +begin_no+ " and " +end_no;
	    
	    ResultSet rs=con.getRs(mysql);
		int i=0;
		String partname="";
		String partid="";
		while(rs.next()){
		i++;partname=rs.getString("partname");
		partid=rs.getString("partid");
	 %>
	<tr onmouseover='$(this).css({"background":"#cee1ed"});' onmouseout='$(this).css({"background":"#fff"});'>
    <td  align="left"><% if("0".equals(rs.getString("sjid"))){ out.print("顶级栏目");}else{out.print(rs.getString("sjname"));}%></td>
    <td  align="left"><%=partname %></td>
    <td width="140" align="center"><% if(rs.getInt("isxj")>0){out.print("有");}else{out.print("无");} %></td>
    <td width="140" align="center"><%=rs.getDate("addtime") %></td>
    <td width="160" align="center">
    <span class="area"><a title="进入_<%=partname %>_子栏目"  href="<%=basePath%>webadmin/info/part.jsp?sid=<%=partid %>"> 子栏目 </a></span> 
    <span class="area"><a title="<%=partname %>_修改" rel="gb_page_center[600,200]" href="<%=basePath%>webadmin/info/part.jsp?act=e&cid=<%=partid%>"> 编辑 </a></span> 
    <span class="area"><a href="javascript:confirmDelete('<%=basePath%>webadmin/info/part.jsp?act=d&cid=<%=partid%>&sid=<%=sid %>');"> 删除 </a></span></td>
    </tr>
   <%} 
   if(intPageCount>1){
   %>
   <tr>
    <td colspan="5" align="center">
     第<%=intPage%>页 共<%=intPageCount%>页 
<a href="<%=basePath%>webadmin/info/part.jsp?page=1&sid=<%=sid %>">首页</a>
<%if(intPage>1){%><a href="<%=basePath%>webadmin/info/part.jsp?page=<%=intPage-1%>&sid=<%=sid %>">上一页</a><%}%> 
<%if(intPage<intPageCount){%><a href="<%=basePath%>webadmin/info/part.jsp?page=<%=intPage+1%>&sid=<%=sid %>">下一页</a><%}%> 
<a href="<%=basePath%>webadmin/info/part.jsp?page=<%=intPageCount%>&sid=<%=sid %>">尾页</a>
   </td>
   </tr>
   <%} }%>
 </table>
 <% } con.close();%>
  </body>
</html>
